package com.tianjipms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tianjipms.entity.Opinion;
import com.tianjipms.entity.Vehicle;
import com.tianjipms.service.OpinionService;
import com.tianjipms.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/opinion")
public class OpinionController {
    @Resource
    private OpinionService opinionService;
    //添加投诉
    @PostMapping("/add")
    public Result addOpinion(@RequestBody Opinion opinion){
        return Result.ok(opinionService.save(opinion));
    }
    //删除投诉
    @DeleteMapping("/delete/{id}")
    public Result deleteNotice(@PathVariable int id) {
        if (opinionService.removeById(id)){
            return Result.ok().message("公告删除成功");
        }
        return Result.error().message("公告删除失败");
    }
    //查找投诉
    @GetMapping("/listAll")
    public Result listAll(@RequestParam(defaultValue = "1") Long pageNum,
                          @RequestParam(defaultValue = "5") Long pageSize) {
        IPage<Opinion> page = new Page<>(pageNum,pageSize);
        return Result.ok(opinionService.page(page));
    }
    //按id分页查询投诉
    @GetMapping("/list")
    public Result listByUserId(@RequestParam("userId") Long userId,
                               @RequestParam(defaultValue = "1") Long pageNum,
                               @RequestParam(defaultValue = "5") Long pageSize){
        IPage<Opinion> page = new Page<>(pageNum, pageSize);
        opinionService.findOpinionListByPage(page,userId);
        return Result.ok(page);
    }

}
